/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;

import Bean.Alumno;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author arturo
 */
public class AlumnoDao {
    
    public static  Connection conn;
    static String url ="jdbc:mysql://localhost/";
    static String base = "Base";
    static String user = "root";
    static String pass = "";
    
    
    public static void conectar() throws ClassNotFoundException, SQLException{
    
        Class.forName("com.mysql.jdbc.Driver");
        conn = (Connection) DriverManager.getConnection(url+base, user, pass);
        
    }
    
    public static void desconectar() throws SQLException{
        
        conn.close();
    }
    
    
   public boolean validar(Alumno a) throws SQLException{
       
       PreparedStatement ps = conn.prepareStatement("SELECT * FROM `ALUMNO` WHERE no_cuenta=? and password=?");
   
       ps.setString(1, a.getNumCta());
       ps.setString(2, a.getPassword());
       
       ResultSet rs = ps.executeQuery();
       
       return rs.next();
       
   }
   
   public Alumno DatosAlumno(String numCta) throws SQLException{
   
       PreparedStatement ps = conn.prepareStatement("SELECT * FROM `ALUMNO`WHERE no_cuenta=?");
       ps.setString(1, numCta);
       ResultSet rs = ps.executeQuery();
       
       if(rs.next()){
       Alumno a = new Alumno();
       a.setId_alumno(rs.getInt(1));
       a.setNumCta(rs.getString(2));
       a.setPassword(rs.getString(3));
       a.setId_nombre_alumno(rs.getInt(4));
       a.setId_direccion(rs.getInt(5));
       
             
       return a;
       }
       
          
       return null;
       
       
   }
   
   /*
    public List<Usuario> selectAll() throws SQLException{
        List<Usuario> all = new ArrayList<Usuario>();
        String sql = "SELECT * FROM `Usuarios`";
        PreparedStatement ps = conn.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while(rs.next()){
            Usuario u = new Usuario();
            u.setId(rs.getInt(1));
            u.setUser(rs.getString(2));
            u.setPass(rs.getString(3));
            all.add(u);
        }
        return all;

    }
*/
    
}
